package edu.fdzc.learn.service.impl;

import edu.fdzc.learn.entity.Homework;
import edu.fdzc.learn.mapper.HomeworkMapper;
import edu.fdzc.learn.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HomeworkServiceImpl implements HomeworkService {

    @Autowired
    private HomeworkMapper homeworkMapper;

    @Override
    public void add(Homework homework) {
        homework.setCreatedAt(LocalDateTime.now());
        homeworkMapper.insert(homework);
    }

    @Override
    public void deleteById(int id) {
        homeworkMapper.delete(id);
    }

    @Override
    public void deleteByIds(int[] ids) {
        for(int id : ids){
            homeworkMapper.delete(id);
        }
    }

    @Override
    public void update(Homework homework) {
        homeworkMapper.update(homework);
    }

    @Override
    public Homework findByid(int id) {
        Homework h = homeworkMapper.findById(id);
        return h;
    }

    @Override
    public List<Homework> findAll(int courseId) {
        List<Homework> list = homeworkMapper.findAll(courseId);
        return list;
    }
}
